/* wehhttpd
* Copyright (c) 2008 Jeffery Myers
*
* This package is free software;  you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "httpd.h"
#include "textUtils.h"

bool WeeHTTPRequest::getParam ( const char* param, std::string &val ) const
{
  val = "";
  if (!param)
    return false;

  std::string p;
  tolower(param,p);

  std::map<std::string, std::vector<std::string> >::const_iterator itr = parameters.find(p);
  if ( itr != parameters.end() )
  {
    if (itr->second.size())
      val = itr->second[itr->second.size()-1];
    return true;
  } 
  return false;
}

bool WeeHTTPRequest::getParam ( const std::string &param, std::string &val ) const
{
  val = "";

  std::string p;
  tolower(param,p);

  std::map<std::string, std::vector<std::string> >::const_iterator itr = parameters.find(p);
  if ( itr != parameters.end() )
  {
    if (itr->second.size())
      val = itr->second[itr->second.size()-1];
    return true;
  } 
  return false;
}

bool WeeHTTPRequest::getParam ( const char* param, std::vector<std::string> &val ) const
{
  val.clear();
  if (!param)
    return false;

  std::string p;
  tolower(param,p);

  std::map<std::string, std::vector<std::string> >::const_iterator itr = parameters.find(p);
  if ( itr != parameters.end() )
  {
    val = itr->second;
    return true;
  } 
  return false;
}

bool WeeHTTPRequest::getParam ( const std::string &param, std::vector<std::string> &val ) const
{
  val.clear();

  std::string p;
  tolower(param,p);

  std::map<std::string, std::vector<std::string> >::const_iterator itr = parameters.find(p);
  if ( itr != parameters.end() )
  {
    val = itr->second;
    return true;
  } 
  return false;
}

bool WeeHTTPRequest::getParam(const char* param) const
{
  if (!param)
    return false;

  std::string p;
  tolower(param,p);

  return parameters.find(p) != parameters.end();
}


bool WeeHTTPRequest::getParam(const std::string &param) const
{
  std::string p;
  tolower(param,p);

  return parameters.find(p) != parameters.end();
}

// Local Variables: ***
// mode: C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
